<template>
  <div class="base-container" id="main">
    <t-steps :current="activeForm" status="process" :onChange="onCurChanged">
      <t-step-item title="验收申请表" :content="isSubmit('acceptanceId')">
      </t-step-item>
    </t-steps>
    <t-loading text="加载中..." :fullscreen="false" attach="#main" :loading="applyLoading" size="medium">
    </t-loading>
    <t-alert v-if="site_tag==='jtt'" theme="info" title="科技项目验收文件清单：">
      <div slot="message">
        <p class="span-txt">
          项目承担单位申请验收时，应提供以下验收文件、资料及成果（专利、样机、样品等），供验收单位或评估机构审查。
        </p>
        <p class="span-title">
          一、验收文件资料
        </p>
        <p class="span-txt">
          1、《江西省交通运输厅科技项目验收申请表》（见附表1）；
        </p>
        <p class="span-txt">
          2、《江西省交通运输厅科技项目任务书（合同）》；
        </p>
        <p class="span-txt">
          3、项目研究工作总结，主要内容包括：
        </p>
        <p class="span-sub-txt">
          ⑴ 合同执行情况；
        </p>
        <p class="span-sub-txt">
          ⑵ 研究工作开展情况；
        </p>
        <p class="span-sub-txt">
          ⑶ 主要研究内容及研究方法；
        </p>
        <p class="span-sub-txt">
          ⑷ 主要研究成果概述。特别要说明主要的科学发现和创新之处，并列出具体的内容和必要的数据；
        </p>
        <p class="span-sub-txt">
          ⑸ 研究成果的科学意义和应用前景（对基础研究，着重阐明其科学意义；对应用基础研究，着重阐明其应用前景）；学术界的反映和引用；国际合作与交流的情况；转入其它重大科技计划的情况；
        </p>
        <p class="span-sub-txt">
          ⑹ 主要研究成果、完成的论著和技术经济指标；
        </p>
        <p class="span-sub-txt">
          ⑺ 存在问题。
        </p>
        <p class="span-txt">
          4、项目研究（技术）报告（按照中华人民共和国交通行业标准JT/T483—2002《交通科技报告编写规则》编写）；
        </p>
        <p class="span-txt">
          5、科技查新报告；
        </p>
        <p class="span-txt">
          6、产品测试（检测）报告；
        </p>
        <p class="span-txt">
          7、用户使用报告（见附表2）；
        </p>
        <p class="span-txt">
          8、经济和社会效益分析报告
        </p>
        <p class="span-txt">
          9、科技项目经费（预）决算表及财务报告（见附表4、5）；。
        </p>
        <p class="span-title">
          （如申请结题验收，只需提交第1、2、3、4、9款等规定的材料）
        </p>
        <p class="span-title">
          二、其他相关资料及各类证明材料
        </p>
        <p class="span-txt">
          1、已获成果、专利及发表论文等一览表（见附表3）；
        </p>
        <p class="span-txt">
          2、项目所购置的仪器、设备等固定资产清单（见附表6）；
        </p>
        <p class="span-txt">
          3、测试、研制样机、样品的图片及数据，各类证明材料；
        </p>
        <p class="span-txt">
          4、项目研究成果简介（见附表7）；
        </p>
        <p class="span-txt">
          5、科技成果公开承诺书（见附表8）；
        </p>
        <p class="span-txt">
          6、项目研究绩效情况表（见附表9）；
        </p>
        <p class="span-txt">
          7、江西省交通运输厅科技项目研究成果（见附表10）。
        </p>
        <p class="span-txt">
          8、其他相关材料。
        </p>
      </div>
    </t-alert>
    <t-alert v-else theme="info" title="科技项目验收文件清单：">
      <div slot="message">
        <p class="span-txt">
          项目承担单位申请验收时，应提供以下验收文件、资料及成果（专利、样机、样品等），供验收单位或评估机构审查。
        </p>
        <p class="span-title">
          一、验收文件资料
        </p>
        <p class="span-txt">
          1、《江西省交通投资集团有限责任公司科技项目验收申请表》（见附表1）；
        </p>
        <p class="span-txt">
          2、《江西省交通投资集团有限责任公司科技项目任务书（合同）》；
        </p>
        <p class="span-txt">
          3、项目研究工作总结，主要内容包括：
        </p>
        <p class="span-sub-txt">
          ⑴ 合同执行情况；
        </p>
        <p class="span-sub-txt">
          ⑵ 研究工作开展情况；
        </p>
        <p class="span-sub-txt">
          ⑶ 主要研究内容及研究方法；
        </p>
        <p class="span-sub-txt">
          ⑷ 主要研究成果概述。特别要说明主要的科学发现和创新之处，并列出具体的内容和必要的数据；
        </p>
        <p class="span-sub-txt">
          ⑸ 研究成果的科学意义和应用前景（对基础研究，着重阐明其科学意义；对应用基础研究，着重阐明其应用前景）；学术界的反映和引用；国际合作与交流的情况；转入其它重大科技计划的情况；
        </p>
        <p class="span-sub-txt">
          ⑹ 主要研究成果、完成的论著和技术经济指标；
        </p>
        <p class="span-sub-txt">
          ⑺ 存在问题。
        </p>
        <p class="span-txt">
          4、项目研究（技术）报告（按照中华人民共和国交通行业标准JT/T483—2002《交通科技报告编写规则》编写）；
        </p>
        <p class="span-txt">
          5、科技查新报告；
        </p>
        <p class="span-txt">
          6、产品测试（检测）报告；
        </p>
        <p class="span-txt">
          7、用户使用报告（见附表2）；
        </p>
        <p class="span-txt">
          8、经济和社会效益分析报告
        </p>
        <p class="span-txt">
          9、科技项目经费（预）决算表及财务报告（见附表4、5）；
        </p>
        <p class="span-title">
          （如申请结题验收，只需提交第1、2、3、4、9款等规定的材料）
        </p>
        <p class="span-title">
          二、其他相关资料及各类证明材料
        </p>
        <p class="span-txt">
          1、已获成果、专利及发表论文等一览表（见附表3）；
        </p>
        <p class="span-txt">
          2、项目所购置的仪器、设备等固定资产清单（见附表6）；
        </p>
        <p class="span-txt">
          3、测试、研制样机、样品的图片及数据，各类证明材料；
        </p>
        <p class="span-txt">
          4、项目研究成果简介（见附表7）；
        </p>
        <p class="span-txt">
          5、科技成果公开承诺书（见附表8）；
        </p>
        <p class="span-txt">
          6、项目研究绩效情况表（见附表9）；
        </p>
        <p class="span-txt">
          7、江西省交通投资集团有限责任公司科技项目研究成果（见附表10）。
        </p>
        <p class="span-txt">
          8、其他相关材料。
        </p>
      </div>
    </t-alert>
    <!-- 基本信息 -->
    <t-form ref="form" :key="activeForm" v-if="activeForm === 0" class="step-form table-form" :data="formData0"
            :rules="rules0"
            labelWidth="180px">
      <t-row>
        <t-col :span="2" class="title">项目名称</t-col>
        <t-col :span="10">{{ contractData.projectName }}</t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title">承担单位</t-col>
        <t-col :span="10">{{ projectData.declareDeptName }}</t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title">合作单位</t-col>
        <t-col :span="10">{{ companyList.join(',') }}</t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title">项目起止时间</t-col>
        <t-col :span="4">{{ contractData.startDate.substring(0, 4) }} 年 {{ contractData.startDate.substring(5, 7) }} 月 至
          {{ contractData.completeDate.substring(0, 4) }} 年 {{ contractData.completeDate.substring(5, 7) }} 月
        </t-col>
        <t-col :span="2" class="title">项目编号</t-col>
        <t-col :span="4">{{ projectData.projectNum }}</t-col>
      </t-row>
      <t-row>
        <t-col :span="2" class="title"><span class="require">*</span>申请验收形式</t-col>
        <t-col :span="4">
          <t-form-item name="applyType">
            <t-radio-group v-model="formData0.applyType" defaultValue="1" :options="dict.type.apply_type"></t-radio-group>
          </t-form-item>
        </t-col>
        <t-col :span="2" class="title"><span class="require">*</span>联系人</t-col>
        <t-col :span="4">
          <t-form-item name="linker">
            <t-input clearable v-model="formData0.linker"></t-input>
          </t-form-item>
        </t-col>

      </t-row>
      <t-row>
        <t-col :span="2" class="title"><span class="require">*</span>申请验收时间</t-col>
        <t-col :span="4">
          <t-form-item name="acceptanceDate">
            <t-date-picker clearable v-model="formData0.acceptanceDate">

            </t-date-picker>
          </t-form-item>

        </t-col>
        <t-col :span="2" class="title"><span class="require">*</span>联系电话</t-col>
        <t-col :span="4">
          <t-form-item name="linkerPhone">
            <t-input clearable placeholder="请输入手机号" v-model="formData0.linkerPhone"></t-input>
          </t-form-item>
        </t-col>

      </t-row>
      <t-row style="min-height: 300px">
        <t-col :span="2" class="title"><span class="require">*</span> <a :href="site_tag==='jtt'?`${file_domain}/view/模板/验收申请材料模板.docx`:`${file_domain}/view/模板/验收申请材料模板.docx`" class="t-button-link"  target="_blank">提供验收的技术文件清单(模版)</a></t-col>
        <t-col :span="10" style="justify-content: center">
          <t-table size="small" row-key="id" :columns="projectFileColumns" :data="projectFileData">
            <template #id="{row, rowIndex}">
              {{ rowIndex+1 }}
            </template>
            <template #op="{row}">
              <file-upload tips="限制pdf" accept="application/pdf" v-model="row.fileIds" :moduleKey="row.moduleKey"
                           :fileList="row.fileLists"
                           :multiple="true">
                <t-button variant="outline">
                  <t-icon name="cloud-upload" slot="icon"/>
                  点击上传
                </t-button>
              </file-upload>
            </template>
            <template #c1="{row}">
              <a v-if="row.c3" class="t-button-link" :href="`${file_domain}/${row.c3}`" target="_blank">{{ row.c1 }}</a>
              <div v-else>{{ row.c1 }}</div>
            </template>
          </t-table>
        </t-col>
      </t-row>
      <t-row style="min-height: 300px">
        <t-col :span="2" class="title">其他相关资料及各类证明材料</t-col>
        <t-col :span="10" style="justify-content: center">
          <t-table size="small" row-key="id" :columns="projectFileColumns" :data="projectFileData2">
            <template #id="{row, rowIndex}">
              {{ rowIndex+1 }}
            </template>
            <template #op="{row}">
              <file-upload v-if="row.moduleKey!=='projectQTXGCL'" tips="限制pdf" accept="application/pdf" v-model="row.fileIds" :moduleKey="row.moduleKey"
                           :fileList="row.fileLists"
                           :multiple="true">
                <t-button variant="outline">
                  <t-icon name="cloud-upload" slot="icon"/>
                  点击上传
                </t-button>
              </file-upload>
              <file-upload v-else v-model="row.fileIds" :moduleKey="row.moduleKey"
                           :fileList="row.fileLists"
                           :multiple="true">
                <t-button variant="outline">
                  <t-icon name="cloud-upload" slot="icon"/>
                  点击上传
                </t-button>
              </file-upload>
            </template>
            <template #c1="{row}">
              <a v-if="row.c3" class="t-button-link" :href="`${file_domain}/${row.c3}`" target="_blank">{{ row.c1 }}</a>
              <div v-else>{{ row.c1 }}</div>
            </template>
          </t-table>
        </t-col>
      </t-row>
      <t-row style="margin-top: 24px">
        <t-col style="border: 0;margin: 0px;padding: 0px !important" :span="11" class="query-form-inline">
          <t-button theme="primary" @click="onSubmit0(1)">暂存</t-button>
          <t-tooltip v-if="projectData.projectStatus !=='27' " :content="isOldProject==='1'?'提交后不会进入审批流程':'提交后不可再编辑会进入审批流程'">
            <t-button :disabled="isCommit" theme="primary" @click="onSubmit0(2)" >
              {{ isOldProject === '1' ? '提交' : '提交到单位管理员' }}
            </t-button>
          </t-tooltip>
          <!--        <t-button theme="primary" @click="onSubmit0(2)">下一步</t-button>-->
        </t-col>
        <t-col style="border: 0;margin: 0px;padding: 0px !important" :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </t-form>
  </div>
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'
import FileUpload from "@/components/FileUpload/index.vue"
import {getFiles} from "@/api/common";

export default {
  name: "acceptance_apply",
  dicts: ["apply_type"],
  components: {
    FileUpload
  },
  data() {
    return {
      site_tag: import.meta.env.VITE_SITE_TAG,
      file_domain: VITE_FILE_DOMAIN,
      projectFileData: [
        {
          id: 1,
          c1: import.meta.env.VITE_SITE_TAG === 'jtt' ? "《江西省交通运输厅科技项目验收申请表》（需要盖章）" : "《江西省交通投资集团有限责任公司科技项目验收申请表》（需要盖章）",
          c2: "是",
          moduleKey: "projectYSSQB",
          fileIds: [],
          fileLists: [],
          require: true,
        },
        {
          id: 2,
          c1: import.meta.env.VITE_SITE_TAG === 'jtt' ? "《江西省交通运输厅科技项目任务书（合同）》" : "《江西省交通投资集团有限责任公司科技项目任务书（合同）》",
          c2: "是",
          moduleKey: "projectRWS",
          fileIds: [],
          fileLists: [],
          require: true,
        },
        {
          id: 3,
          c1: "项目研究工作总结",
          c2: "是",
          moduleKey: "projectYJGZZJ",
          fileIds: [],
          fileLists: [],
          require: true,
        },
        {
          id: 4,
          c1: "项目研究（技术）报告（按照中华人民共和国交通行业标准JT/T483—2002《交通科技报告编写规则》编写）",
          c2: "是",
          moduleKey: "projectYJBG",
          fileIds: [],
          fileLists: [],
          require: true,
        },
        {
          id: 5,
          c1: "科技查新报告",
          c2: "否",
          moduleKey: "projectCXBG",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 6,
          c1: "产品测试（检测）报告",
          c2: "否",
          moduleKey: "projectCPCSBG",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 7,
          c1: "用户使用报告",
          c2: "否",
          moduleKey: "projectYHSYBG",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 8,
          c1: "经济和社会效益分析报告",
          c2: "否",
          moduleKey: "projectJJHSHFXBG",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 9,
          c1: "科技项目经费（预）决算表（需要盖章）",
          c2: "是",
          moduleKey: "projectJFJSBJCWBG",
          fileIds: [],
          fileLists: [],
          require: true,
        },
        {
          id: 10,
          c1: "经费支出50万元以上（含）的项目，需提交具有审计资质的会计师事务所出具的项目验收财务审计报告（需包含佐证材料复印件）。经费支出50万元以下的项目，由项目承担单位出具项目验收财务报告和经费支出记账凭证及相关附件（如发票、签收单、合同等）或具有审计资质的会计师事务所出具的项目验收财务审计报告（需包含佐证材料复印件）",
          c2: "是",
          moduleKey: "projectJFCWBG",
          fileIds: [],
          fileLists: [],
          require: true,
        },
      ],
      projectFileData2: [
        {
          id: 1,
          c1: "已获成果、专利及发表论文等一览表",
          c2: "否",
          moduleKey: "projectCGB",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 2,
          c1: "项目所购置的仪器、设备等固定资产清单",
          c2: "否",
          moduleKey: "projectGDZCD",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 3,
          c1: "测试、研制样机、样品的图片及数据，各类证明材料",
          c2: "否",
          moduleKey: "projectCCYPZMCL",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 4,
          c1: "项目研究成果简介",
          c2: "否",
          moduleKey: "projectYJCGJJ",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 5,
          c1: "科技成果公开承诺书",
          c2: "否",
          moduleKey: "projectCGGKCNS",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 6,
          c1: "项目研究绩效情况表",
          c2: "否",
          moduleKey: "projectYJJXQKB",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 7,
          c1: import.meta.env.VITE_SITE_TAG === 'jtt' ? "江西省交通运输厅科技项目研究成果" : "江西省交通投资集团有限责任公司科技项目研究成果",
          c2: "否",
          moduleKey: "projectYJCG",
          fileIds: [],
          fileLists: [],
          require: false,
        },
        {
          id: 8,
          c1: '其他相关材料',
          c2: "否",
          moduleKey: "projectQTXGCL",
          fileIds: [],
          fileLists: [],
          require: false,
        },
      ],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },

        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "操作",
          align: "left",
        },
      ],
      applyLoading: false,
      isCommit: false,
      activeForm: 0,
      formData0: {
        applyType: '',
        linker: '',
        linkerPhone: '',
        acceptanceDate: '',
        sysAttMainVo: {
          sysAttMainIds: []
        },
        fileLists: []
      },
      companyList: [],
      rules0: {
        applyType: [
          {
            required: true,
            message: "申请验收形式不能为空",
          }
        ],
        linker: [
          {
            required: true,
            message: "联系人不能为空",
          }
        ],
        linkerPhone: [
          {
            required: true,
            message: "联系电话不能为空",
          },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "联系电话请输入正确的手机号码",
          },
        ],
        acceptanceDate: [
          {
            required: true,
            message: "申请验收时间不能为空",
          }
        ],
        'sysAttMainVo.sysAttMainIds': [
          {required: true, validator: (val) => val.length > 0, message: "提供验收的技术文件清单不能为空", type: "error"}
        ],
      },
      projectId: null,
      projectData: {
        startDate: '',
        endDate: '',
      },
      contractData: {
        startDate: '',
        completeDate: '',
      },
      dialog: {
        objId: null
      },
      taskId: null,
      isOldProject: '0'
    }
  },
  watch: {
    activeForm: {
      immediate: true,
      handler(val) {
        const targetEle = document.getElementById("main")
        if (targetEle) {
          const {pos, top} = targetEle.style;
          targetEle.style.position = 'relative';
          targetEle.style.top = '-100px';
          targetEle.scrollIntoView({behavior: 'smooth', block: 'start', inline: "nearest"});
          targetEle.style.top = top;
          targetEle.style.position = pos;
        }
      }
    }
  },
  created() {
    this.isOldProject = this.$route.query.isOldProject || '0';
    if (this.isOldProject === '1') {
      this.projectFileData = this.projectFileData.map(val => ({...val, c2: '否', require: false}))
    }
    const projectId = this.$route.params && this.$route.params.taskId;
    if (!projectId) {
      this.$message.error("缺少项目id");
      return false;
    }
    this.projectId = projectId;
    this.dialog.objId = projectId;
    this.taskId = projectId;
    const activeForm = Number(sessionStorage.getItem(`${this.taskId}-acceptance-activeForm`)) || 0;
    // 获取项目详情
    this.applyLoading = true;
    this.$api.kjxm.project.get(Number(this.projectId)).then(pro => {
      this.projectData = pro.data;
      this.onCurChanged(activeForm, 0);
    }).catch((e) => {
      this.applyLoading = false;
      this.$message.error(e.toString());
    });
    this.$api.kjxm.contract.getByProject(Number(this.projectId)).then(pro => {
      this.contractData = pro.data;
    }).catch((e) => {
      this.applyLoading = false;
      this.$message.error(e.toString());
    });

    this.$api.kjxm.project.companyGet(Number(this.projectId), 3).then(pro => {
      this.companyList = pro.data.filter(val => val.type === '2').map(val => val.name)
    }).catch((e) => {
      this.applyLoading = false;
      this.$message.error(e.toString());
    });
  },
  methods: {
    onCurChanged(cur, pre) {
      this.applyLoading = true;
      if (Number(cur) === 0) {
        if (sessionStorage.getItem(`${this.taskId}-acceptanceId`)) {
          const acceptanceId = Number(sessionStorage.getItem(`${this.taskId}-acceptanceId`));
          getFiles(acceptanceId).then((res) => {
            // const ids = [];
            // if (res.data && res.data.length) {
            //   res.data.forEach((item) => {
            //     ids.push(item.id);
            //     this.formData0.fileLists.push({ name: item.fileName, url: item.fullFilePath, id: item.id, filePath: item.filePath })
            //   })
            //   this.formData0.sysAttMainVo.sysAttMainIds = ids;
            // }
            const files = {}
            res.data.forEach((item) => {
              if (!files[item.moduleKey]) {
                files[item.moduleKey] = []
              }
              files[item.moduleKey].push({
                name: item.fileName,
                url: item.fullFilePath,
                id: item.id,
                filePath: item.filePath
              })
            })
            this.projectFileData.forEach((val, index) => {
              this.projectFileData[index].fileLists = files[val.moduleKey] || [];
              this.projectFileData[index].fileIds = files[val.moduleKey]?.map(val => val.id) || [];
            })
            this.projectFileData2.forEach((val, index) => {
              this.projectFileData2[index].fileLists = files[val.moduleKey] || [];
              this.projectFileData2[index].fileIds = files[val.moduleKey]?.map(val => val.id) || [];
            })
          });
          this.$api.kjxm.acceptance.get(acceptanceId).then(response => {
            if (response.data) {
              response.data.sysAttMainVo = response.data.sysAttMainVo || {sysAttMainIds: []}
              Object.assign(this.formData0, response.data)
            }
            this.activeForm = cur;
            sessionStorage.setItem(`${this.taskId}-acceptance-activeForm`, cur);
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-acceptance-activeForm`, cur);
          this.applyLoading = false;
        }
      }
    },
    isSubmit(name) {
      if (sessionStorage.getItem(`${this.taskId}-acceptance-${name}`)) {
        return '已提交'
      }
      return '未提交';
    },
    isSubmitStatus(name) {
      return !!sessionStorage.getItem(`${this.taskId}-acceptance-${name}`);
    },
    onSubmit0(type) {
      const sysAttMainIds = []
      this.projectFileData.forEach(val => {
        sysAttMainIds.push(...val.fileIds)
      })
      this.projectFileData2.forEach(val => {
        sysAttMainIds.push(...val.fileIds)
      })
      if (type === 1) {
        this.applyLoading = true;
        this.isCommit = true;
        if (!sessionStorage.getItem(`${this.taskId}-acceptance-acceptanceId`)) {
          this.$api.kjxm.acceptance.add({
            ...this.formData0,
            projectId: this.projectId,
            sysAttMainVo: {
              sysAttMainIds,
            }
          }).then(response => {
            sessionStorage.setItem(`${this.taskId}-acceptanceId`, response.data.id)
            sessionStorage.setItem(`${this.taskId}-acceptance-acceptanceId`, response.data.id)
            this.$message.success("暂存成功");
            this.applyLoading = false;
            this.isCommit = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.isCommit = false;
            this.$message.error(e.toString());
          });
        } else {
          this.$api.kjxm.acceptance.update({
            ...this.formData0,
            projectId: this.projectId,
            id: Number(sessionStorage.getItem(`${this.taskId}-acceptance-acceptanceId`)),
            sysAttMainVo: {
              sysAttMainIds,
            }
          }).then(response => {
            this.$message.success("暂存成功");
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        }

      } else {
        this.$refs.form.validate().then((validateResult) => {
          if (validateResult === true) {
            const isValidate = this.projectFileData.every(val => {
              if (val.require && val.fileIds.length <= 0) {
                this.$message.error(`提供验收的技术文件清单：需要上传${val.c1}`);
                return false;
              }
              return true
            })
            if (!isValidate) {
              return false
            }
            this.applyLoading = true;
            this.isCommit = true;
            if (!sessionStorage.getItem(`${this.taskId}-acceptance-acceptanceId`)) {
              this.$api.kjxm.acceptance.add({
                ...this.formData0,
                projectId: this.projectId,
                sysAttMainVo: {
                  sysAttMainIds,
                }
              }).then(response => {
                sessionStorage.setItem(`${this.taskId}-acceptanceId`, response.data.id)
                sessionStorage.setItem(`${this.taskId}-acceptance-acceptanceId`, response.data.id)
                if (this.isOldProject === '1') {
                  this.$api.kjxm.acceptance.oldSubmit({
                    projectId: this.projectId,
                    id: Number(sessionStorage.getItem(`${this.taskId}-acceptance-acceptanceId`)),
                  }).then(response => {
                    this.$message.success("提交成功");
                    this.applyLoading = false;
                    this.isCommit = false;
                    this.close()
                  }).catch((e) => {
                    this.applyLoading = false;
                    this.isCommit = false;
                    this.$message.error(e.toString());
                  });
                } else {
                  this.$api.kjxm.acceptance.submit({
                    projectId: this.projectId,
                    id: Number(sessionStorage.getItem(`${this.taskId}-acceptance-acceptanceId`)),
                  }).then(response => {
                    this.$message.success("提交成功");
                    this.applyLoading = false;
                    this.isCommit = false;
                    this.close()
                  }).catch((e) => {
                    this.$message.error(e.toString());
                  });
                }


              }).catch((e) => {
                this.applyLoading = false;
                this.isCommit = false;
                this.$message.error(e.toString());
              });
            } else {
              this.$api.kjxm.acceptance.update({
                ...this.formData0,
                projectId: this.projectId,
                id: Number(sessionStorage.getItem(`${this.taskId}-acceptance-acceptanceId`)),
                sysAttMainVo: {
                  sysAttMainIds,
                }
              }).then(response => {
                if (this.isOldProject === '1') {
                  this.$api.kjxm.acceptance.oldSubmit({
                    projectId: this.projectId,
                    id: Number(sessionStorage.getItem(`${this.taskId}-acceptance-acceptanceId`)),
                  }).then(response => {
                    this.$message.success("提交成功");
                    this.applyLoading = false;
                    this.isCommit = false;
                    this.close()
                  }).catch((e) => {
                    this.applyLoading = false;
                    this.isCommit = false;
                    this.$message.error(e.toString());
                  });
                } else {
                  this.$api.kjxm.acceptance.submit({
                    projectId: this.projectId,
                    id: Number(sessionStorage.getItem(`${this.taskId}-acceptance-acceptanceId`)),
                  }).then(response => {
                    this.$message.success("提交成功");
                    this.applyLoading = false;
                    this.isCommit = false;
                    this.close()
                  }).catch((e) => {
                    this.applyLoading = false;
                    this.isCommit = false;
                    this.$message.error(e.toString());
                  });
                }


              }).catch((e) => {
                this.applyLoading = false;
                this.isCommit = false;
                this.$message.error(e.toString());
              });
            }

          } else {
            const firstError = Object.values(validateResult)[0]?.[0]?.message;
            this.$message.error(firstError);
          }
        })

      }
    },
    close() {
      this.applyLoading = false;
      setTimeout(() => {
        this.$tab.closeOpenPage({path: "/kjxm/acceptance/project-my"});
      }, 1000)
    }
  }
}
</script>

<style scoped lang="less">
.span-title {
  font-weight: bold;
}

.span-sub-txt {
  margin-left: 20px;
}

.step-form {
  padding: 0 24px;
}

.t-row {
  margin-bottom: 14px;
}

.step-card {
  height: 100%;
  margin-bottom: 14px;
}

.table-form {
  /deep/ .t-radio.t-is-disabled .t-radio__label {
    color: unset
  }

  /deep/ .t-is-error .t-input__extra {
    position: static;
  }

  /deep/ .t-form__label {
    display: none;
  }

  .t-form__item {
    width: 100%;
  }

  .t-row {
    align-items: stretch;
    margin-bottom: 0px;
    //.t-form__item{
    //  width: 100%;
    //}
    .require {
      color: red;
      margin-right: 3px;
    }

    .t-col {
      border: 1px solid #ddd;
      color: #333;
      min-height: 37px;
      padding: 4px !important;
      //overflow: hidden;
      display: flex;
      align-items: center;
      margin: 0px -1px -1px 0px;
    }

    .title {
      background-color: #FAFAFA;
      justify-content: center;
      margin: 0px -1px -1px 0px;
      color: #606266;
    }
  }
}
</style>
